package com.teafriend.controller;

import com.teafriend.entity.Tea;
import com.teafriend.service.TeaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 茶叶控制器
 * @author 欧楚杨
 */
@RestController
@RequestMapping("/chuyangc/tea")
@Api(tags = "茶叶相关的请求")
public class TeaController {
    @Autowired
    TeaService teaService;

    @GetMapping("/listtea")
    @ApiOperation("查询所有茶叶")
    @ApiImplicitParam()
    public List<Tea> listTea(){
        return teaService.list();
    }

    @DeleteMapping("/deltea/{id}")
    @ApiOperation("根据茶叶id删除数据")
    @ApiImplicitParam(name = "茶叶id",value = "id",required = true)
    public boolean delTea(@PathVariable("id") Integer id){
        return teaService.removeById(id);
    }

    @PostMapping("/addtea")
    @ApiOperation("添加茶叶")
    @ApiImplicitParam(name = "茶叶实体类对象",value = "tea",required = true)
    public boolean addTea(@RequestBody Tea tea){
        return teaService.save(tea);
    }

    @GetMapping("/searchtea/{id}")
    @ApiOperation("根据id查找茶叶")
    @ApiImplicitParam(name = "茶叶id",value = "id",required = true)
    public Tea searchTea(@PathVariable Integer id){
        return teaService.getById(id);
    }

    @PostMapping("/updatetea")
    @ApiOperation("根据茶叶id修改信息")
    @ApiImplicitParam(name = "茶叶实体类对象",value = "tea",required = true)
    public boolean updateTea(@RequestBody Tea tea){
        return teaService.updateById(tea);
    }
}
